﻿@model IEnumerable<AppsGenerator.Models.AppTableView>

@{
    ViewBag.Title = "Generate";
}

@if (Model != null)
{

    <link rel="stylesheet" href="~/Content/Wizard.css"/>
    <script src="~/Scripts/Wizard.js"></script>
    
<h2>Generate Controllers For</h2>
    <div class="container">
        <div class="stepwizard">
            <div class="stepwizard-row setup-panel">
                <div class="stepwizard-step">
                    <a href="#step-1" type="button" class="btn btn-primary btn-circle">1</a>
                    <p>Choose Tables</p>
                </div>
                <div class="stepwizard-step">
                    <a href="#step-2" type="button" class="btn btn-default btn-circle theme" disabled="disabled">2</a>
                    <p>Choose Theme</p>
                </div>
                <div class="stepwizard-step">
                    <a href="#step-3" type="button" class="btn btn-default btn-circle" disabled="disabled">3</a>
                    <p>Finish</p>
                </div>
            </div>
        </div>

        @using (Html.BeginForm())
        {
        @Html.AntiForgeryToken()
        @Html.Hidden("appId")
            <div class="row setup-content" id="step-1">
                <div class="col-xs-12">
                    <div class="col-md-12">
                        <table class="table">
                            <tr>
                                <th>
                                    <input type="checkbox" id="checkAll" data-checked="false" />
                                    <span id="checkAllSpan">Check All</span>
                                </th>
                            </tr>

                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        <input type="checkbox" name="selectedTables" value="@item.Name" />
                                        @item.Name
                                    </td>
                                </tr>
                            }

                        </table>

                        <button class="btn btn-primary nextBtn btn-lg pull-right theme" type="button">Next</button>
                    </div>
                </div>
            </div>
            <div class="row setup-content" id="step-2">
                <div class="col-xs-12">
                    <div class="col-md-12">
                      
                        @Html.Action("GetAll","Themes")
                       
                        <button class="btn btn-primary nextBtn btn-lg pull-right" type="button">Next</button>
                    </div>
                </div>
            </div>
            <div class="row setup-content" id="step-3">
                <div class="col-xs-12">
                    <div class="col-md-12">
                        <h3> Finish </h3>
                        <p>
                            We will generate application files with the selected tables
                        </p>
                        <button class="btn btn-success btn-lg pull-right" type="submit">Generate</button>
                    </div>
                </div>
            </div>
        }
    </div>

    <script>
        $(document).ready(function () {
            var selectedId = 0;
            $("#checkAll").change(function () {
                var checkAll = $(this).attr('data-checked');
                if (checkAll == 'true') {
                    $(":checkbox").prop('checked', false);
                    $(this).attr('data-checked', 'false');
                    $('#checkAllSpan').text('Check All');
                } else if (checkAll == 'false') {
                    $(":checkbox").prop('checked', true);
                    $(this).attr('data-checked', 'true');
                    $('#checkAllSpan').text('Uncheck All');
                }
            });
    });
    </script>
}
else
{
    <div class="alert-warning">
        <h1>
            No Tables Found
        </h1>
    </div>
}
